package com.xinqi.modules.chat.chat.message.controller.web;

import com.xinqi.common.base.response.R;
import com.xinqi.common.satoken.utils.LoginHelper;
import com.xinqi.modules.chat.chat.message.dto.req.ChatEmojiMessageCreateDTO;
import com.xinqi.modules.chat.chat.message.dto.req.ChatEmojiMessageDeleteDTO;
import com.xinqi.modules.chat.chat.message.dto.rsp.ChatEmojiMessageResultDTO;
import com.xinqi.modules.chat.chat.message.service.ChatEmojiMessageService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * WEB -- 聊天消息自定义表情
 *
 * @author: yyzhen
 * @date: 2023/07/11
 */
@Validated
@RestController
@RequestMapping("/web/chat-emoji-message")
@RequiredArgsConstructor
public class ChatEmojiMessageWebController {
    private final ChatEmojiMessageService chatEmojiMessageService;

    @Operation(summary = "新增自定义表情")
    @PostMapping("/add")
    public R<Long> insert(@Validated @RequestBody ChatEmojiMessageCreateDTO dto) {
        return R.data(chatEmojiMessageService.insert(dto, LoginHelper.getXqLoginUser()));
    }

    @Operation(summary = "移动到前面")
    @GetMapping("/move-front/{id}")
    public R<Boolean> moveToFront(@NotNull(message = "{chat.message.emoji.id.not.blank}") @PathVariable("id") Long id) {
        return R.data(chatEmojiMessageService.moveToFront(id, LoginHelper.getXqLoginUser()));
    }

    @Operation(summary = "删除自定义表情")
    @PostMapping("/remove")
    public R<Boolean> remove(@Validated @RequestBody ChatEmojiMessageDeleteDTO dto) {
        return R.data(chatEmojiMessageService.deleteById(dto));
    }

    @Operation(summary = "查询用户的自定义表情")
    @GetMapping("/list-user")
    public R<List<ChatEmojiMessageResultDTO>> listByUser() {
        return R.data(chatEmojiMessageService.listByUserId(LoginHelper.getUserId()));
    }

}
